define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/withdraw/index' + location.search,
                    // add_url: 'user/withdraw/add',
                    // edit_url: 'user/withdraw/edit',
                    // del_url: 'user/withdraw/del',
                    multi_url: 'user/withdraw/multi',
                    import_url: 'user/withdraw/import',
                    table: 'user_withdraw',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user.username', title: __('提现用户昵称'), operate:'LIKE'},
                        {field: 'user.mobile', title: __('提现用户手机号'), operate:'LIKE'},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'status', title: __('Status'), searchList: {0:'待审核',1:'成功',2:'失败'}, formatter: Table.api.formatter.status},
                        {field: 'remark', title: __('Remark'), operate: 'LIKE'},
                        {field: 'accountnumber', title: __('Accountnumber'), operate: 'LIKE'},
                        {field: 'realname', title: __('Realname'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate',  buttons: [{
                                name: '审核',
                                hidden:function(row){
                                    if(row.status != 0){
                                        return true;
                                    }
                                },
                                text: __('审核'),
                                classname: 'btn btn-danger btn-xs btn-detail btn-dialog',
                                url: function(row){
                                    return 'user/withdraw/edit/ids/'+row.id;
                                }
                            }], title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
